package com.market2.demo;

import java.io.IOException;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.market2.dto.ActionDto;
import com.market2.dto.ContratDto;
import com.market2.dto.StockOptionDto;
import com.market2.session.ContratManagerRemote;
import com.market2.utils.NamingUtil;

public class ContratBeanDemo {

	public static void main(String[] args) throws IOException {
		try {
			Context context = new InitialContext();
			ContratManagerRemote manager = (ContratManagerRemote) context
					.lookup(NamingUtil
							.getBeanName(ContratManagerRemote.class));

			List<ContratDto> result = manager.getAllContrats();
			System.out.println("Nombre de contrats : " + result.size());
			
			if(result.size() > 0) {
				for(ContratDto c : result) {
					System.out.println("Contrat : " + c.getNumero());
					System.out.println("    Titulaire : " + c.getTitulaire());
					System.out.println("    Qt : " + c.getQuantite());
					
					if(c instanceof StockOptionDto) {
						StockOptionDto so = (StockOptionDto) c;
						System.out.println("    Date ech : " + so.getDateEcheance());
					}
					
					if(c instanceof ActionDto) {
						ActionDto ac = (ActionDto) c;
						System.out.println("    ISIN : " + ac.getIsin());
					}
				}
			}
			
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
}
